package team.szm.scd.utils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.function.Function;

public class TimeUtils {
    //这天是周一
    public final static LocalDate testDateToday0 = LocalDate.of(2022, 4, 4);
    private static Function<Void, LocalDate> testNowDateFunction = (v) -> testDateToday0;
    private static Function<Void, LocalTime> testNowTimeFunction = (v) -> LocalTime.now();

    public static void setTestNowDateFunction(Function<Void, LocalDate> function) throws IllegalAccessException {
        if (EnvUtils.getEnv() != EnvUtils.EnvType.TEST) {
            throw new IllegalAccessException();
        }
        testNowDateFunction = function;
    }

    public static LocalDate testNowDate() throws IllegalAccessException {
        EnvUtils.AssertEnv(EnvUtils.EnvType.TEST);
        return testNowDateFunction.apply(null);
    }

    public static LocalTime testNowTime() throws IllegalAccessException {
        EnvUtils.AssertEnv(EnvUtils.EnvType.TEST);
        return testNowTimeFunction.apply(null);
    }

    public static void setTestNowTimeFunction(Function<Void, LocalTime> testNowTimeFunction) {
        TimeUtils.testNowTimeFunction = testNowTimeFunction;
    }
}
